﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ExamSystem.util
{
    /// <summary>
    /// 功能助手类
    /// </summary>
    public class FunHelper
    {
        /// <summary>
        /// 提示信息并跳转页面
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="url"></param>
        public static void LayerAlter(System.Web.UI.Page page, string msg, string url)
        {
            //为了防止输出的msg中有双引号，导致alert不能提示，所以需要把双引号替换为单引号
            msg = msg.Replace('\"', '\'');
            //输出信息中有\r\n换行符，需要替换掉，不然不能输出
            msg = msg.Replace("\r", "");
            msg = msg.Replace("\n", "");
            string script = "<script>layer.alert(\"" + msg + "\", { icon: 0 , closeBtn: 0 } , function () {document.location.href = '" + url + "';})</script>";
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", script);           
        }
        /// <summary>
        /// 提示信息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="url"></param>
        public static void LayerAlter(System.Web.UI.Page page, string msg)
        {
            //为了防止输出的msg中有双引号，导致alert不能提示，所以需要把双引号替换为单引号
            msg = msg.Replace('\"', '\'');
            //输出信息中有\r\n换行符，需要替换掉，不然不能输出
            msg = msg.Replace("\r", "");
            msg = msg.Replace("\n", "");
            string script = "<script>layer.alert(\"" + msg + "\",{icon: 0})</script>";
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", script);
        }
    }
}